<?php
//header("Content-Type: application/xml; charset=ISO-8859-1");
header('Content-type: text/xml');
include("config.inc");
include("include/database.php");
/*
 * by SONY K Wibisono
 * e-mail : sony@sonywibisono.com
 */

//Place code here
function rss_list(){
    global $db,$site_url;
    $date = date("D, j M Y G:i:s O");

    $sql="select a.id,a.title,a.excerpt,a.contents 
            from _post_contents a,_post_category b
          where a.post_category=b.id order by a.id";
    $result=$db->query($sql);
    $site_rss=$site_url."rss.php";
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n
    <rss version=\"2.0\">\r\n
    <channel>\r\n
    <lastBuildDate>$date</lastBuildDate>\n
    <pubDate>$date</pubDate>\r\n
    <title>Inherent RSS Feed</title>\r\n
    <description><![CDATA[Rss Feed for Inherent]]></description>\r\n
    <link>$site_rss</link>\r\n
    <managingEditor>sony@sonywibisono.com (Sony Wibisono)</managingEditor>\r\n
    <webMaster>dikti.vicon@yahoo.com (Dikti Vicon)</webMaster>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        $link=htmlentities($site_url."index.php?mod=posting&action=detail&id=$id");
        $description=htmlentities($contents);
        $excerpt=htmlentities($excerpt);
        echo "<item>\r\n
      <title>$title</title>\r\n
      <link>$link</link>\r\n
      <description><![CDATA[$excerpt]]>$description</description>\r\n
      <guid isPermaLink=\"true\">$link</guid>\n
      </item>\r\n";
       
    }
    echo "</channel>\r\n
        </rss>\r\n";
}
function event_list(){
    global $db,$site_url;
    $date = date("D, j M Y G:i:s O");

    $sql="select a.*,b.category_name 
            from _event_events a,_event_category b
          where a.event_category=b.id order by a.id";
    $result=$db->query($sql);
    $site_rss=$site_url."rss.php?action=event";
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n
    <rss version=\"2.0\">\r\n
    <channel>\r\n
    <lastBuildDate>$date</lastBuildDate>\n
    <pubDate>$date</pubDate>\r\n
    <title>Inherent RSS Feed</title>\r\n
    <description><![CDATA[Rss Feed for Inherent]]></description>\r\n
    <link>$site_rss</link>\r\n
    <managingEditor>sony@sonywibisono.com (Sony Wibisono)</managingEditor>\r\n
    <webMaster>dikti.vicon@yahoo.com (Dikti Vicon)</webMaster>\r\n";
    while ($row=$db->fetch_array($result)){
        extract($row);
        $link=htmlentities($site_url."index.php?mod=events&action=show&id=$id");
        $pos=strpos($event_content,"<!--more-->");
        if ($pos>-1){
        $short_desc=substr($event_content,0, $pos); 
        } else $short_desc=$event_content;
        $description=htmlentities($short_desc);
        $excerpt=htmlentities($event_content);
        echo "<item>\r\n
      <title>$event_title</title>\r\n
      <link>$link</link>\r\n
      <description><![CDATA[$description]]>$description</description>\r\n
      <guid isPermaLink=\"true\">$link</guid>\n
      </item>\r\n";
       
    }
    echo "</channel>\r\n
        </rss>\r\n";
}
global $is_admin,$login_status,$action;
switch ($action){
    case 'news':
        rss_list();
        break;
    default:
        event_list();
}


?>